Find Quarter Dates and month start and end dates
Find Quarter Dates and month start and end dates
DECLARE @curDate DATETIME = GETDATE()
DECLARE @FromDate DATETIME =
CASE WHEN MONTH(@curDate) > 3 and MONTH(@curDate) <= 9 THEN CAST(CAST(YEAR(@curDate) AS VARCHAR) + '-03-01' AS DATE)
WHEN MONTH(@curDate) > 9 THEN CAST(CAST(YEAR(@curDate) AS VARCHAR) + '-10-01' AS DATE)
ELSE CAST(CAST(YEAR(@curDate)-1 AS VARCHAR) + '-10-01' AS DATE) END
DECLARE @ToDate DATETIME =
CASE WHEN MONTH(@curDate) > 3 and MONTH(@curDate) <= 9 THEN CAST(CAST(YEAR(@curDate) AS VARCHAR) + '-09-30' AS DATE)
WHEN MONTH(@curDate) > 9 THEN CAST(CAST(YEAR(@curDate)+1 AS VARCHAR) + '-03-31' AS DATE)
ELSE CAST(CAST(YEAR(@curDate) AS VARCHAR) + '-03-31' AS DATE) END
SELECT CAST(@FromDate AS DATE),CAST(@ToDate AS DATE)
--Quater START end Dates
DECLARE @FromDate DATETIME = DATEADD(q, DATEDIFF(q, 0, @curDate), 0)
DECLARE @ToDate DATETIME = DATEADD(d, -1, DATEADD(q, DATEDIFF(q, 0, @curDate) + 1, 0))
-- Month Start Date End Date
DECLARE @fromdate datetime = DATEADD(M,DATEDIFF(M,0,@curDate),0)
DECLARE @toDate datetime = DATEADD(M,DATEDIFF(M,0,@curDate)+1,-1)
----
Login for comment